package org.karelun.rabbit.rcp.property.tab;

import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.karelun.rabbit.graph.GraphPackage;
import org.karelun.rabbit.graph.Texted;

public class TextPropertySection extends BasePropertySection<Texted> {
	
	private Text text;
	
	private ISWTObservableValue textObserver;
	
	public TextPropertySection() {
	}
	
	@Override
	protected String getSectionTitle() {
		return "Texted";
	}
	
	@Override
	protected void doCreateControl(Composite parent) {
		parent.setLayout(new GridLayout());
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		text = new Text(parent,SWT.BORDER);
		text.setLayoutData(new GridData(GridData.FILL_BOTH));
		textObserver=WidgetProperties.text(SWT.Modify).observe(text);
	}
	
	@Override
	protected void dataBinding() {
		Texted selected = getSelectedObject();
		dataBinding(textObserver, selected,GraphPackage.Literals.TEXTED__TEXT);
	}
	
	@Override
	public void refresh() {
		if(text==null||text.isDisposed()){
			return;
		}
		text.setEnabled(isEditable());
	}
}
